/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package project;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author jon
 */
public class AgreeTo {
    private int client_number;
    private int lease_id;

    public AgreeTo(int client_number, int lease_id) {
        this.client_number = client_number;
        this.lease_id = lease_id;
    }

    
    /**
     * @return the client_number
     */
    public int getClient_number() {
        return client_number;
    }

    /**
     * @param client_number the client_number to set
     */
    public void setClient_number(int client_number) {
        this.client_number = client_number;
    }

    /**
     * @return the lease_id
     */
    public int getLease_id() {
        return lease_id;
    }

    /**
     * @param lease_id the lease_id to set
     */
    public void setLease_id(int lease_id) {
        this.lease_id = lease_id;
    }

    public void insert()
    {
        try
        {
            String host = "jdbc:oracle:thin:@localhost:1521:xe";
            String username = "jon";
            String password = "chaosecco";
            String driverName = "oracle.jdbc.driver.OracleDriver";
            Class.forName(driverName);

            Connection connection = DriverManager.getConnection(host,
                    username, password);
            System.out.print("Connected successfully.");
            String insertQuery = "INSERT INTO AGREE_TO(" +
                    "client_number, " +
                    "lease_number)"  +
                    "VALUES(?, ?)";
            PreparedStatement ps = connection.prepareStatement(insertQuery);
            ps.setInt(1, client_number);
            ps.setInt(2, lease_id);
            ps.executeUpdate();

            connection.close();
        }

        catch (SQLException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }

        catch(ClassNotFoundException e)
        {
            System.out.println("ERROR: " + e.getMessage());
        }
    }
}
